﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>工作日志</title>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="css/ydui.css?v=1.1.7" rel="stylesheet" />
    <script src="js/ydui.flexible.js"></script>
    <link rel="stylesheet" type="text/css" href="css/all.css?v=2018041801" />
    <link href="css/weui.css" rel="stylesheet" />
    <style type="text/css">
        .mui-btn {
            border: none;
        }

        .mui-btn-blue {
            color: #1cbb7f;
        }

        .mui-dtpicker-title {
            color: #2A2A2A;
        }

        .mui-picker {
            background: #F5F5F5;
        }

        .cell-left {
            width: 50px;
        }
    </style>
</head>
<body ms-controller="recordview" class="ms-controller">
    <div class="g-flexview">
        <!--<header class="m-navbar">
            <div class="navbar-center">
                <span class="navbar-title">工作日志</span>
            </div>
        </header>-->
        <div class="g-scrollview">
            <div class="m-cell">
                <div class="cell-item">
                    <div class="cell-left">日志时间</div>
                    <div class="cell-right">{{ModelData.workDate}}</div>
                </div>
                <div class="cell-item">
                    <div class="cell-left">任务</div>
                    <div class="cell-right cell-arrow">
                        <input type="text" readonly="readonly" id="task" class="cell-input" placeholder="请选择任务" autocomplete="off" ms-duplex="taskName">
                    </div>
                </div>
            </div>

            <div ms-if="logStatus!=''&&logStatus!='1'">
                <div class="m-cell">
                    <div class="cell-item">
                        <div class="cell-left">工作日志</div>
                        <div class="cell-right">
                            时长（{{ModelData.billingHours}}）
                        </div>
                    </div>
                    <div class="cell-item">
                        <div class="cell-right" style="-webkit-justify-content:flex-start;justify-content:flex-start;text-align:left;">
                            {{ModelData.billingHoursDesc}}
                        </div>
                    </div>
                </div>

                <div class="m-cell">
                    <div class="cell-item">
                        <div class="cell-left">加班日志</div>
                        <div class="cell-right">
                            时长（{{ModelData.overworkHours}}）
                        </div>
                    </div>
                    <div class="cell-item">
                        <div class="cell-right" style="-webkit-justify-content:flex-start;justify-content:flex-start;text-align:left;">
                            {{ModelData.overworkHoursDesc}}
                        </div>
                    </div>
                </div>

            </div>

            <div ms-if="logStatus==''||logStatus=='1'">

                <div class="m-cell">
                    <div class="cell-item">
                        <div class="cell-left">工作日志</div>
                        <div class="cell-right" id="showPicker">
                            时长<span class="m-spinner" id="J_Quantity" style="margin-left:5px;">
                                <a href="javascript:;" class="J_Del"></a>
                                <input type="text" class="J_Input" placeholder="" ms-duplex="ModelData.billingHours" />
                                <a href="javascript:;" class="J_Add"></a>
                            </span>
                        </div>
                    </div>
                    <div class="cell-item">
                        <div class="cell-right">
                            <textarea class="cell-textarea" placeholder="请输入工作内容" ms-duplex="ModelData.billingHoursDesc" style="height:3rem;"></textarea>
                        </div>
                    </div>
                </div>

                <div class="m-cell">
                    <div class="cell-item">
                        <div class="cell-left">加班日志</div>
                        <div class="cell-right" id="showPicker2">
                            时长<span class="m-spinner" id="J_Quantity2" style="margin-left:5px;">
                                <a href="javascript:;" class="J_Del2"></a>
                                <input type="text" class="J_Input2" placeholder="" ms-duplex="ModelData.overworkHours" />
                                <a href="javascript:;" class="J_Add2"></a>
                            </span>
                        </div>
                    </div>
                    <div class="cell-item">
                        <div class="cell-right">
                            <textarea class="cell-textarea" placeholder="请输入加班内容" ms-duplex="ModelData.overworkHoursDesc" style="height:3rem;"></textarea>
                        </div>
                    </div>
                </div>

            </div>
        </div>
        <div class="m-actionsheet" id="J_ActionSheet">
            <a href="javascript:void(0)" ms-repeat-el="WorkList" class="actionsheet-item" ms-click="SelWork(el)">{{el.projectName}}-{{el.taskName}}</a>
        </div>
        <footer class="m-tabbar" style="padding: 0;" ms-if="logStatus==''||logStatus=='1'">
            <div class="tabbar-item">
                <a href="javascript:;" class="btn-block btn-primary" style="border-radius: 0;font-size: .3rem;" ms-click="Save()">提交</a>
            </div>
        </footer>
    </div>

    <script src="https://cdn.bootcss.com/jquery/2.2.0/jquery.min.js"></script>
    <script src="../../JS/layer/layer.m.js"></script>
    <script src="js/ydui.js"></script>
    <script src="../../JS/avalon1.47.js"></script>
    <script src="../../JS/ComFunJS.js"></script>
    <script src="https://res.wx.qq.com/open/libs/weuijs/1.0.0/weui.min.js"></script>
    <script>

        var hours = 7.5;
        var $myAs = $('#J_ActionSheet');
        $(function () {
            if (!ComFunJS.iswx()) {
                window.location.href = "../UI_Error.html?msg=请在微信端打开";
            }

            $('#task').on('click', function () {
                $myAs.actionSheet('open');
            });
            //$(".actionsheet-item").on("click", function () {
            //    $('#task').val($(this).text());
            //    $myAs.actionSheet('close');
            //})


            $.getJSON("/API/VIEWAPI.ashx?Action=OUTAPI_GETWORKCONFIG&r=" + Math.random(), { }, function (resultData) {
                hours = parseFloat(resultData.Result);

                $('#J_Quantity').spinner({
                    input: '.J_Input',
                    add: '.J_Add',
                    minus: '.J_Del',
                    min: 0,
                    unit: 0.5,
                    max: hours,
                    callback: function (value, $ele) {
                        model.ModelData.billingHours = value;
                    }
                });

            })

            $('#J_Quantity2').spinner({
                input: '.J_Input2',
                add: '.J_Add2',
                minus: '.J_Del2',
                min: 0,
                unit: 0.5,
                max: 24,
                callback: function (value, $ele) {
                    model.ModelData.overworkHours = value;
                }
            });

        });

        var model = avalon.define({
            $id: "recordview",
            rwdate: ComFunJS.getQueryString("rwdate"),
            WorkList: [],
            SelWork: function (el) {
                model.ModelData.taskId = el.taskId;
                model.taskName = el.taskName;
                $myAs.actionSheet('close');

                if (el.taskId) {
                    $.getJSON("/API/VIEWAPI.ashx?Action=OUTAPI_GETLOGDETAILBYUDT&r=" + Math.random(), { "workDate": model.rwdate, "taskId": el.taskId }, function (resultData) {
                        if (resultData.ErrorMsg == "" && resultData.Result && resultData.Result != "[]") {
                            var wk = JSON.parse(resultData.Result);
                            if (wk && wk.length > 0) {
                                model.logStatus = wk[0].logStatus;
                                model.ModelData.logId = wk[0].logId;
                                if (wk[0].billingHours) {
                                    model.ModelData.billingHours = wk[0].billingHours;
                                }
                                model.ModelData.billingHoursDesc = wk[0].billingHoursDesc;

                                if (wk[0].overworkHours) {
                                    model.ModelData.overworkHours = wk[0].overworkHours;
                                }
                                model.ModelData.overworkHoursDesc = wk[0].overworkHoursDesc;

                               
                            } else {
                                model.logStatus = "";
                                model.ModelData.logId = "";
                                model.ModelData.billingHours = hours;
                                model.ModelData.billingHoursDesc = "";

                                model.ModelData.overworkHours = 0;
                                model.ModelData.overworkHoursDesc = "";

                            }
                        }

                    })
                }
            },
            logStatus: "",
            taskName: "",
            ModelData: { "logId": "", "taskId": "", "workDate": "", "billingHours": "7.5", "billingHoursDesc": "", "overworkHours": "0", "overworkHoursDesc": "" },
            Save: function () {
                if (!model.ModelData.taskId) {
                    ComFunJS.winwarning("请选择任务");
                    return;
                }
                if (!model.ModelData.billingHoursDesc && !model.ModelData.overworkHoursDesc) {
                    ComFunJS.winwarning("请输入工作日志或者加班日志");
                    return;
                }

                var sumhours = 0;
                if (model.ModelData.billingHoursDesc) {
                    sumhours += parseFloat(model.ModelData.billingHours);
                }
                if (model.ModelData.overworkHoursDesc) {
                    sumhours += parseFloat(model.ModelData.overworkHours);
                }

                if (sumhours > 24) {
                    ComFunJS.winwarning("总时长不能超过24小时");
                    return;
                }
                var desp = "确定提交吗？";
                if (model.ModelData.billingHoursDesc && parseFloat(model.ModelData.billingHours) < hours) {
                    desp = "当天正常工时不足" + hours + "小时，是否继续提交？";
                }


                ComFunJS.confirm(desp, function () {

                    $.getJSON("/API/VIEWAPI.ashx?Action=OUTAPI_SUBMITLOG&r=" + Math.random(), model.ModelData.$model, function (resultData) {
                        if (resultData.ErrorMsg == "") {
                            ComFunJS.winsuccess("提交成功");
                            setTimeout(function () {
                                window.location.href = "indexrl.html";
                            }, 2000);
                        }

                    })

                })

            }

        });
        avalon.ready(function () {

            if (!model.rwdate) {
                model.rwdate = ComFunJS.getnowdate("yyyy-mm-dd");
            }

            model.ModelData.workDate = model.rwdate;

            $.getJSON("/API/VIEWAPI.ashx?Action=OUTAPI_GETTASKBYUDS&r=" + Math.random(), { "queryDate": model.rwdate, "status": 2 }, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    model.WorkList = JSON.parse(resultData.Result);
                }

            })


        })


    </script>
</body>
</html>
